package servlet;


import utils.VerifyCodeUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet( value = "/vcode.s")
public class VcodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //必须在输出验证码之前获取会话对象
        HttpSession session = req.getSession();
        //生成验证码，同时向页面输出验证码图片
        String vcode = VerifyCodeUtils.outputImage(resp);
        //将验证码保存到会话中
        session.setAttribute("vcode",vcode);
    }
}
